package cn.itcast.jdbc;

import java.sql.*;
/*
数据获取
待解决问题，是否是最后一行
 */
public class JDBC_Demo5 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement statement = null;
        try {
            // 1.注册驱动
            Class.forName("com.mysql.jdbc.Driver");

            // 2.获取连接对象
            conn = DriverManager.getConnection("jdbc:mysql:///test");

            // 3.获取sql执行对象（本次练习insert）
            statement = conn.createStatement();

            // 4.执行sql
            // String sql = "insert into emp values(7758,null,null,null,null,null,null,null)";
            String sql = "select * from emp";
            ResultSet resultSet = statement.executeQuery(sql);

            resultSet.next();
            int _1 = resultSet.getInt(1);
            String _2 = resultSet.getString(2);
            String _3 = resultSet.getString(3);
            System.out.print(_1);
            System.out.print(_2);
            System.out.println(_3);


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally{
            if(conn != null)
            {
                //资源释放
                try {
                    conn.close();
                    if(statement != null)
                    {
                        statement.close();
                    }
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }

            }
        }
    }


}
